package org.junyi.log.controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.junyi.log.service.LogServer;
import org.junyi.pojo.Log;
import org.junyi.util.ArchivesLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("/log")
public class LogControl
{
	@Autowired
	LogServer logServer;
	@RequestMapping("/queryAll")
	@ArchivesLog(operationType="显示:",operationName="显示日志") 
	public void queryUser(String limit, String offset,
			HttpServletResponse response) throws IOException
	{
		List<Log> data = logServer.query();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", data.size());//
		map.put("rows", data);//
		JSONObject jsonArray = JSONObject.fromObject(map);
		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		response.getWriter().write(jsonArray.toString());
	}
	
	@RequestMapping("/del")
	public void delete(HttpServletResponse response) throws IOException{
		Integer i=logServer.deleteAll();
		if(i>0){
			response.getWriter().print("success");
		}else{
			response.getWriter().print("error");
		}
	}
}
